package com.easyadmin.pro.tool;

import com.easyadmin.pro.common.context.BeanContext;
import com.easyadmin.pro.common.context.UserContext;
import com.easyadmin.pro.modules.sys.entity.UserEntity;
import com.easyadmin.pro.modules.sys.entity.UserRoleEntity;

import java.util.Objects;

/**
 * packageName com.easyadmin.pro.tool
 *
 * @author 骑着蚂蚁去上天
 * @version JDK 17
 * @className WebUtils
 * @date 2024/4/22
 * @description 用户信息获取工具类
 */
public class WebUtils {

    private static UserContext USER_CONTEXT = null;

    public static void init() {
        if (Objects.isNull(USER_CONTEXT)) {
            USER_CONTEXT = BeanContext.getBean(UserContext.class);
        }

    }

    public static UserEntity getUserInfo() {
        init();
        return USER_CONTEXT.getCurrentInfo();
    }

    public static String getUserName() {
        init();
        return USER_CONTEXT.getCurrentUserName();
    }

    public static Long getUserId() {
        init();
        return USER_CONTEXT.getCurrentUserId();
    }

    public static String getUserTrueName() {
        init();
        return USER_CONTEXT.getCurrentTrueName();
    }

    public static UserRoleEntity getUserRoleInfo() {
        init();
        return USER_CONTEXT.getCurrentRoleInfo();
    }

}